package hikari.managers;

import com.gooddies.wiring.annotations.Wire;
import com.gooddies.wiring.annotations.WiringComponent;
import hikari.gui.panels.ModifyPanel;
import hikari.hcomponents.physics.BoxRigidBody;
import hikari.hcomponents.physics.IRigidBody;
import hikari.hcomponents.physics.PhysicsData;
import hikari.objects3d.Basic3dObject;

/**
 * @author sad
 */
@WiringComponent(singleton = true, lazy = true)
public class PhysicManager {

    @Wire
    private SelectionManager selectionManager;
    @Wire
    private ModifyPanel modifyPanel;

    private PhysicManager() {
    }

    private PhysicsData createPhysicsData(Basic3dObject object) {
        PhysicsData data = new PhysicsData();
        IRigidBody rigidBody = new BoxRigidBody(object.getMeshSceneNode(), data);
        data.setRigidBody(rigidBody);
        return data;
    }

    public void addPhysicToSelectedObject() {
        Basic3dObject object = selectionManager.getCurrentSelectedObject();
        if (object == null) {
            return;
        }

        object.addHComponent(createPhysicsData(object));
        modifyPanel.reFillPanel();
    }
}
